<template>
    <div id="member">
        <el-col :span="24" class="action-bar">
            <el-select v-model="questionSheet" clearable placeholder="答卷批次" style="margin:0 20px;">
                <el-option
                v-for="item in questionSheetOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
                <el-button type="primary" size="medium" @click="search">筛选</el-button>
            </el-col>
        <el-table
        :data="tableData"
        style="width: 100%">
        <el-table-column
            prop="date"
            label="头像"
            width="100">
            <template slot-scope="scope">
                <div>
                    <img :src="scope.row.photo_url" alt="" style="width:60px;border-radius:50%;height:60px;object-fit:cover">
                </div>
            </template>
        </el-table-column>
        <el-table-column
            prop="name"
            label="姓名/昵称"
            width="180">
            <template slot-scope="scope">
                <div>{{scope.row.realname?scope.row.realname:scope.row.nickname}}</div>
            </template>
        </el-table-column>
        <el-table-column
            prop="submit_time"
            label="提交答卷时间"
            min-width="100"
            >
        </el-table-column>
        <el-table-column
            prop="sort_name"
            label="答卷批次">
        </el-table-column>
        <el-table-column
            prop="status_name"
            label="评分状态"
            
            >
            <template slot-scope="scope">
                <el-tag type="warning" v-show="scope.row.status==1">{{scope.row.status_name}}</el-tag>
                <el-tag  v-show="scope.row.status!=1">{{scope.row.status_name}}</el-tag>
            </template>
        </el-table-column>
        <el-table-column
            prop="score"
            width="180"
            label="成绩">
        </el-table-column>
        <el-table-column
            prop="address"
            label="操作"
            min-width="200"
            >
            <template slot-scope="scope">
                <div>
                   <el-button type="primary" @click="showScore(scope.row.id)">评分</el-button>
                </div>
            </template>
        </el-table-column>
        </el-table>
        <el-col :span="24" class="footer-bar">
			<div class="page-code">
				<el-pagination
					background
					:page-size="16"
					layout="prev, pager, next"
					:total="totalPage"
					@current-change="pageChange"
						>
				</el-pagination>
			</div>
    </el-col>

		<el-dialog title="评分" :visible.sync="scroeVisible" @close="initData">
            <el-form label-position="top" label-width="400px" >
                <el-form-item :label="item.questions" v-for="(item,index) of questionAnswerList" :key="index">
                    <div>{{item.user_answer}}</div>
                </el-form-item>
                <el-form-item label="评分">
                    <el-input v-model="score" :max="100" :min="0" type="number" placeholder="请输入0-100的分数" @blur="correctScore"></el-input>
                </el-form-item>
            </el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="setScore">提交</el-button>
			</div>
		</el-dialog>
    </div>
</template>
<script>
export default {
    name:'member',
    data() {
        return {
            questionSheetId:'',//选中的答卷
            scroeVisible:false,
            questionSheet:'',//头部筛选的答卷类型
            score:'',//评分分数
            questionSheetOptions:[
                {label:'全部',value:0},
                {label:'一轮答卷',value:1},
                {label:'二轮答卷',value:2}
            ],
            questionAnswerList:'',
            tableData: [{user_info:{}}],
            page:1,
            totalPage:0    
        }
    },
    methods: {
        search(){
            this.page=1;
            this.getUserAnswerList()
        },
        async getUserAnswerList(){
            //获取会员列表
            let params={
                page:this.page,
                limit:16,
                sort:this.questionSheet
            }
            let res=await this.$api.getUserAnswerList(
                params);
            if(res.data.level=='success'){
                this.tableData=res.data.data;
                this.totalPage=res.data.page_info.total;
            }
        },
        pageChange(e){
			//翻页
			this.page=e;
			this.getUserAnswerList();
        },
        showScore(id){
            //显示答题
            this.questionSheetId=id;
            this.scroeVisible=true;
            this.getUserQuestionAnswer()
        },
        async getUserQuestionAnswer(){
            //获取答题详情
            let params={
                id:this.questionSheetId
            }
            let res=await this.$api.getUserQuestionAnswer(params);
            if(res.data.level=='success'){
                this.questionAnswerList=res.data.data
            }
        },
        correctScore(){
            //不能超出100分，小于0分;
            if(this.score<0||this.score>100){
                this.$message({
                    message: '评分不能超出100分，小于0分',
                    type: 'error'
                    });
                    this.score='';
            }
        },
        async setScore(){
            //评分
            if(this.score===''){
                this.$message({
                    message: '评分不能为空',
                    type: 'error'
                    });
                return
            }
            let params={
                id:this.questionSheetId,
                score:this.score
            }
            let res =await this.$api.setScore(params);
            if(res.data.level=='success'){
                    this.$message({
                        message: res.data.message,
                        type: 'success'
                        });
                    this.scroeVisible=false;
                    this.getUserAnswerList()
                }else{
                    this.$message({
                    message: res.data.message,
                    type: 'error'
                    });
                }
        },
        initData(){
            this.score='';
            this.questionAnswerList='';
            this.questionSheetId='';
        },
    },
    mounted() {
        this.getUserAnswerList()
    },
}
</script>
<style lang="scss" scoped>
    .action-bar{
			background-color: #f2f2f2;
			height: 60px;
			margin: 10px 0px;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			padding-left: 20px;
			.action-bar-input{
				width: 250px;
				margin-right: 14px;
      }
      .task-form-text{
				color: #666666;
			}
		}
		.el-table-style{
			width: 100%;
			border: 1px solid #f2f2f2;
		}
		.footer-bar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #f2f2f2;
			padding: 8px;
			margin: 10px 0px;
			box-sizing: border-box;
		}
		.dialog-footer{
			text-align: center;
		}
		.executorList{
			display: flex;
			flex-wrap: wrap;
			div{
				margin:10px;
				border:1px solid #eee;
				border-radius: 5px;
				padding:5px 10px;
			}
		}
</style>